/*
*
* File Name          :  FFT.c
* Description        :  FFT Functions
*/


#include <stdint.h>
#include "circle_api.h"
#include "FFT.h"
#include "ClockCounter.h"

int16_t _FFT_Samples[2*FFT_SAMPLE_LENGTH];
short fx[4];

void FFT_Init() { 

}

void FFT_Calc() {
    FFT_Test1();
}

void FFT_Test1() { 
    short x[2*FFT_SAMPLE_LENGTH]; // input data 16 bit, 4 byte aligned x0r,x0i,x1r,x1i,....
    short y[2*FFT_SAMPLE_LENGTH]; // output data 16 bit,4 byte aligned y0r,y0i,y1r,y1i,....
    short z[2*FFT_SAMPLE_LENGTH];
    uint8_t str[16];
    short i;

    for(i=0; i<2*FFT_SAMPLE_LENGTH; i+=2) { 
        x[i] = 0x4000;
        x[i+1] = 0x0;
    }
    fftR4(y, x, FFT_SAMPLE_LENGTH);
    ifftR4(z, y, FFT_SAMPLE_LENGTH);
    fx[0] = y[128];
    fx[1] = y[129];

    UTIL_int2str( &str[0], y[0], 9, 1 );
    DRAW_DisplayString( 0, 185, str, 10);
    for(i=0; i<6; i++) { 
        UTIL_int2str( &str[0], z[i], 5, 1 );
        DRAW_DisplayString( 0, 170-i*15, str, 6);
    }
}

void FFT_Test2() {
/*
    uint16_t i;
    int16_t _FFT_Output[2*FFT_SAMPLE_LENGTH];

    for(i=0; i<2*FFT_SAMPLE_LENGTH; i+=2) {
        if(i<16)
            _FFT_Samples[i] = 0x4000;
        else
            _FFT_Samples[i] = 0;
        _FFT_Samples[i+1] = 0x0;
    }
    STOPWATCH_START
    fftR4(_FFT_Output, _FFT_Samples, FFT_SAMPLE_LENGTH);
    STOPWATCH_STOP
    CycleCounter_Print(0, 120, 10);
*/
}
